<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 引入vue -->
  <script src="../js/vue.js"></script>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <!-- 引入组件库 -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <!-- 引入jquery -->
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
</head>
<body>
  <div id="app">
    <template>
      <el-table
        :data="tableData"
        style="width: 100%">
        <el-table-column
          prop="name"
          label="栏目名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="description"
          label="栏目描述"
          width="180">
        </el-table-column>
        <el-table-column
          prop="parentId"
          label="所属栏目ID">
        </el-table-column>
      </el-table>
    </template>
  </div>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        tableData: [],
        token: ''
      },
      methods: {
        userLogin() {
          $.ajax({
            url: 'http://47.94.46.113:7788/user/login',
            method: 'POST',
            data: JSON.stringify({
              username: 'admin1',
              password: '123321'
            }),
            contentType: 'application/json',
            success: (res) => {
              // 1.将获取的token保存到data的token中
              this.token = res.data.token
              // 2.请求查询栏目接口
              this.findAllCategories()
            }
          })
        },
        findAllCategories() {
          $.ajax({
            url: 'http://47.94.46.113:7788/category/findAll',
            method: 'GET',
            headers: {
              'Authorization': this.token
            },
            success: (res) => {
              this.tableData = res.data
            }
          })
        }
      },
      created() {
        this.userLogin();
      }
    })
  </script>
</body>
</html>